/*
 * LoginFrame.java
 *
 * Created on Jan 10, 2012, 3:12:08 PM
 */
package kernel_gui.gui.generic.graphic;


import java.awt.AWTError;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;

import kernel_gui.gui.generic.BackGroundPanel;
import kernel_gui.gui.generic.MillionaireFrame;

/**
 *
 * @author Yoyo
 */
public abstract class LoginFrame extends MillionaireFrame {

    /**
	 * 
	 */
	private static final long serialVersionUID = 7368604299660772692L;
	
	/** Creates new form LoginFrame */
    public LoginFrame() {
    	super(false);
        initComponents();
    }

    private void initComponents() {

        LayeredPane = new javax.swing.JLayeredPane();
        LoadingPanel = new javax.swing.JPanel();
        SpinningDollarLabel = new javax.swing.JLabel();
        TopMessageLabel = new javax.swing.JLabel();
        CancelButton = new javax.swing.JButton();
        userNameTextField = new javax.swing.JTextField();
        passwordLabel = new javax.swing.JLabel();
        userNameLabel = new javax.swing.JLabel();
        createUserButton = new javax.swing.JButton();
        passwordTextField = new javax.swing.JPasswordField();
        loginAsAdminCheckBox = new javax.swing.JCheckBox();
        loginButton = new javax.swing.JButton();

        /* My init code */
    	int frameWidth = 219;
    	int frameHeight = 229;
    	this.setBounds(new Rectangle(new Dimension(frameWidth, frameHeight)));
    	this.setIconImage(new javax.swing.ImageIcon("images/Green-Dollar-icon.png").getImage());
       	this.setTitle("Login");
    	LayeredPane.setOpaque(false);
    	LoadingPanel.setVisible(false);
    	LoadingPanel.setOpaque(false);
    	setResizable(false);
    	try{
	    	Toolkit tk = Toolkit.getDefaultToolkit();
	    	int framePosWidth = tk.getScreenSize().width / 2 - frameWidth / 2;
	    	int framePosHeight = tk.getScreenSize().height / 2 - frameHeight / 2;
	    	Point p = new Point(framePosWidth, framePosHeight);
	    	this.setLocation(p);
		}catch(AWTError e){
			/*Nothing to do*/
		}
    	BGPanel = new BackGroundPanel(frameWidth, frameHeight);
        MainPanel = new BackGroundPanel(frameWidth, frameHeight);
    	SpinningDollarLabel.setIcon(new javax.swing.ImageIcon(
    			"images/dollar-spinning.gif")); // NOI18N
    	/* end */


        LayeredPane.setOpaque(true);

        LoadingPanel.setOpaque(false);


        TopMessageLabel.setBackground(new java.awt.Color(51, 102, 0));
        TopMessageLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        TopMessageLabel.setForeground(new java.awt.Color(51, 204, 0));
        TopMessageLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        TopMessageLabel.setText("Loading Please wait");
        TopMessageLabel.setOpaque(true);

        CancelButton.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        CancelButton.setText("Cancel");
        CancelButton.setOpaque(false);
        CancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CancelButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout LoadingPanelLayout = new javax.swing.GroupLayout(LoadingPanel);
        LoadingPanel.setLayout(LoadingPanelLayout);
        LoadingPanelLayout.setHorizontalGroup(
            LoadingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(LoadingPanelLayout.createSequentialGroup()
                .addGap(59, 59, 59)
                .addComponent(SpinningDollarLabel)
                .addContainerGap(61, Short.MAX_VALUE))
            .addGroup(LoadingPanelLayout.createSequentialGroup()
                .addGap(43, 43, 43)
                .addComponent(TopMessageLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(42, 42, 42))
            .addGroup(LoadingPanelLayout.createSequentialGroup()
                .addGap(70, 70, 70)
                .addComponent(CancelButton)
                .addContainerGap(73, Short.MAX_VALUE))
        );
        LoadingPanelLayout.setVerticalGroup(
            LoadingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, LoadingPanelLayout.createSequentialGroup()
                .addContainerGap(53, Short.MAX_VALUE)
                .addComponent(SpinningDollarLabel)
                .addGap(18, 18, 18)
                .addComponent(TopMessageLabel)
                .addGap(34, 34, 34)
                .addComponent(CancelButton)
                .addContainerGap())
        );

        LoadingPanel.setBounds(0, 0, 220, 230);
        LayeredPane.add(LoadingPanel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        MainPanel.setOpaque(false);

        userNameTextField.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        passwordLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        passwordLabel.setText("Password:");

        userNameLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        userNameLabel.setText("User name:");

        createUserButton.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        createUserButton.setText("I'm new");
        createUserButton.setToolTipText("Press here if this is you'r first time");
        createUserButton.setOpaque(false);
        createUserButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                createUserButtonActionPerformed(evt);
            }
        });

        passwordTextField.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        loginAsAdminCheckBox.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        loginAsAdminCheckBox.setText("Login as administrator");
        loginAsAdminCheckBox.setToolTipText("Check if you wish to login with administrator privileges");
        loginAsAdminCheckBox.setOpaque(false);

        loginButton.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        loginButton.setText("Login!");
        loginButton.setOpaque(false);
        loginButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loginButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout MainPanelLayout = new javax.swing.GroupLayout(MainPanel);
        MainPanel.setLayout(MainPanelLayout);
        MainPanelLayout.setHorizontalGroup(
            MainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(MainPanelLayout.createSequentialGroup()
                .addGroup(MainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(MainPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(MainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, MainPanelLayout.createSequentialGroup()
                                .addComponent(passwordLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(passwordTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, MainPanelLayout.createSequentialGroup()
                                .addComponent(userNameLabel)
                                .addGap(18, 18, 18)
                                .addComponent(userNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(MainPanelLayout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(loginAsAdminCheckBox))
                    .addGroup(MainPanelLayout.createSequentialGroup()
                        .addGap(63, 63, 63)
                        .addGroup(MainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(loginButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(createUserButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(14, Short.MAX_VALUE))
        );
        MainPanelLayout.setVerticalGroup(
            MainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(MainPanelLayout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(MainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(userNameLabel)
                    .addComponent(userNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(MainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(passwordLabel)
                    .addComponent(passwordTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(loginAsAdminCheckBox)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 44, Short.MAX_VALUE)
                .addComponent(loginButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(createUserButton)
                .addContainerGap())
        );

        MainPanel.setBounds(0, 0, 220, 230);
        LayeredPane.add(MainPanel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout BGPanelLayout = new javax.swing.GroupLayout(BGPanel);
        BGPanel.setLayout(BGPanelLayout);
        BGPanelLayout.setHorizontalGroup(
            BGPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 222, Short.MAX_VALUE)
            .addGroup(BGPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(LayeredPane, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE))
        );
        BGPanelLayout.setVerticalGroup(
            BGPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 231, Short.MAX_VALUE)
            .addGroup(BGPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(LayeredPane, javax.swing.GroupLayout.DEFAULT_SIZE, 231, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(BGPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(BGPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }

                                           

    protected abstract void loginButtonActionPerformed(java.awt.event.ActionEvent evt);                                                                                                                                

    protected abstract void createUserButtonActionPerformed(java.awt.event.ActionEvent evt);

    protected javax.swing.JPanel BGPanel;
    protected javax.swing.JLayeredPane LayeredPane;
    protected javax.swing.JLabel SpinningDollarLabel;
    protected javax.swing.JLabel TopMessageLabel;
    protected javax.swing.JButton createUserButton;
    protected javax.swing.JCheckBox loginAsAdminCheckBox;
    protected javax.swing.JButton loginButton;
    protected javax.swing.JLabel passwordLabel;
    protected javax.swing.JPasswordField passwordTextField;
    protected javax.swing.JLabel userNameLabel;
    protected javax.swing.JTextField userNameTextField;
}
